package com.zw.fzbilibili.controller;

import com.zw.fzbilibili.common.Result;
import com.zw.fzbilibili.entity.SysUser;
import com.zw.fzbilibili.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 登录验证接口
 * </p>
 *
 * @author zhangwen
 * @since 2022/12/23
 */
@RestController
@RequestMapping(value = "/authentication")
public class JwtAuthController {

    @Autowired
    private AuthService authService;

    @PostMapping(value = "/login")
    public Result createToken(String username, String password) throws AuthenticationException {
        return Result.succ(authService.login(username, password));
    }

    @PostMapping(value = "/register")
    public Result register(@RequestBody SysUser addedUser) throws AuthenticationException {
        return Result.succ(authService.register(addedUser));
    }

}
